<template>
    <div class="pushForm" >
      <el-dialog title="活动推送"  :visible.sync= "refresh" :before-close="handleClose">
        <table class="pushTable" cellspacing="0">
          <tr>
            <td class="pushTd">推送终端</td>
            <td class="pushTd">华财通</td>
            <td class="pushTd">理财师</td>
          </tr>
          <tr>
            <td class="pushTd">推送状态</td>
            <td class="pushTd"><el-checkbox v-model="push_HCT_status" :disabled="push_HCT_disabled">推送</el-checkbox></td>
            <td class="pushTd"><el-checkbox v-model="push_LCS_status" :disabled="push_LCS_disabled">推送</el-checkbox></td>
          </tr>
          <tr>
            <td class="pushTd">推送结果</td>
            <td class="pushTd">{{push_HCT_result}}</td>
            <td class="pushTd">{{push_LCS_result}}</td>
          </tr>
        </table>
        <div slot="footer" class="dialog-footer">
          <el-button @click="closeForm">取 消</el-button>
          <el-button type="primary" @click="submitPush" :disabled="submPushButton" >确 定</el-button>
        </div>
      </el-dialog>
    </div>
</template>


<script type="text/ecmascript-6">
  const loactionOptions = ['首页', '活动中心'];
  import {postLog} from 'api/common/index.js'
  export default {
    props:['actPush'],
    data () {
      return {
        chgPublish: {
          disableNoPublishVisible: false
        },
        push_HCT_status:'',
        push_LCS_status:'',
        push_HCT_result:'',
        push_LCS_result:'',
        push_HCT_disabled:false,
        push_LCS_disabled:false,
        submPushButton:false,
        formLabelWidth: '100px'
      }
    },
    computed:{
      refresh(){
        this.pushFormVisible = this.$store.state.pushFormVisible;
        if(this.pushFormVisible){
          this.getPushStatus();
        }
        return this.$store.state.pushFormVisible;
      }
    },
    methods: {
      handleClose(done) {
        this.closeForm();
      },
      getPushStatus () {
        this.$http.get('/api-active/v1/api/activityCenter/activity/push/' + this.$store.state.pushActId  + '').then((response) => {
          var data = response.body.result;
          if (data.push_HCT_status === 'PUSHED') {
            this.push_HCT_status = true;
            this.push_HCT_disabled = true;
          }else{
            this.push_HCT_status = false;
            this.push_HCT_disabled = false;
          }

          if (data.push_LCS_status === 'PUSHED') {
            this.push_LCS_status = true;
            this.push_LCS_disabled = true;
          }else{
            this.push_LCS_status = false;
            this.push_LCS_disabled = false;
          }

          this.push_LCS_result = data.push_LCS_status_text;
          this.push_HCT_result = data.push_HCT_status_text;

          if(this.push_LCS_disabled && this.push_HCT_disabled){
            this.submPushButton = true;
          }else{
            this.submPushButton = false;
          }
          console.log(' after getPushStatus this.push_HCT_status = ' + this.push_HCT_status + '     this.push_LCS_status = ' + this.push_LCS_status);
        })
      },
      closeForm(){
        this.$store.commit('SET_PushFormVisible', false);
      },
      submitPush () {
        var push_HCT_status ='';
        if(this.push_HCT_status){
          push_HCT_status = 'PUSHED';
        }else{
          push_HCT_status = 'NOT_YET';
        }
        var push_LCS_status ='';
        if(this.push_LCS_status){
          push_LCS_status = 'PUSHED';
        }else{
          push_LCS_status = 'NOT_YET';
        }

        var pashData = {
          "activityId": this.$store.state.pushActId,
          "push_HCT_status": push_HCT_status,
          "push_LCS_status": push_LCS_status
        }

        this.push_HCT_result = '……';
        this.push_LCS_result = '……';

        this.$http.put('/api-active/v1/api/activityCenter/activity/push', pashData).then((response) => {
          var data = response.body
          if (data.resultCode === '200') {
            this.$emit('refreshList');
            this.push_HCT_result = data.result.push_HCT_status_text;
            this.push_LCS_result = data.result.push_LCS_status_text;
            postLog('ACTIVITY_LIST_PUSH', pashData.activityId, this.actPush.name, pashData)
          } else {
            this.push_HCT_result = '推送失败';
            this.push_LCS_result = '推送失败';
          }
        })

      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
  .pushTable
    border: 1px solid gainsboro;
    height: 120px;
    overflow: hidden;
    text-align: center;
    margin :0 auto;

  td {
    width :100px;
    padding: 0;
    margin: 0;
    border: 1px solid gainsboro;
  }

  .pushForm{
    width: 400px;
    margin: 0px auto;
    padding:0;
  }
</style>
